import java.util.Arrays;

public class Solution1475 {
    public int[] finalPrices(int[] prices) {
        int[] ans=new int[prices.length];
        for (int i=prices.length-1;i>=0;i--){
            ans[i]=prices[i];
            for (int j=i+1;j<prices.length;j++){
                if (prices[i]>=prices[j]){
                    ans[i]-=prices[j];
                    break;
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution1475().finalPrices(new int[]{8, 4, 6, 2, 3})));
    }
}
